#include "refraction_effect_ctrl.h"

#include "effects/refraction_effect.h"
#include "graphics/opengl.h"

namespace venus {
const Effect *RefractionEffectCtrlGlut::effect() const { return effect_; }

RefractionEffectCtrlGlut::~RefractionEffectCtrlGlut() { delete effect_; }

bool RefractionEffectCtrlGlut::OnSpecialKey(int key, int x, int y) {
  switch (key) {
    case GLUT_KEY_DOWN:
      this->dec_eta_ratio();
      break;
    case GLUT_KEY_UP:
      this->inc_eta_ratio();
      break;
    default:
      return false;
  }
  return true;
}

bool RefractionEffectCtrlGlut::inc_eta_ratio() {
  float old_val = effect_->eta_ratio();
  float new_val = eta_ratio_.inc(old_val);
  if (old_val == new_val) return false;
  effect_->set_eta_ratio(new_val);
  return true;
}

bool RefractionEffectCtrlGlut::dec_eta_ratio() {
  float old_val = effect_->eta_ratio();
  float new_val = eta_ratio_.dec(old_val);
  if (old_val == new_val) return false;
  effect_->set_eta_ratio(new_val);
  return true;
}

} // namespace venus
